package com.william.yun.yunliwuli.api.rest;

import com.alibaba.fastjson.JSONObject;
import com.william.yun.yunliwuli.api.HttpResponse;
import com.william.yun.yunliwuli.api.request.goods.BrushRequest;
import com.william.yun.yunliwuli.api.request.goods.GoodsAllRequest;
import com.william.yun.yunliwuli.api.request.goods.GoodsRequest;
import com.william.yun.yunliwuli.api.response.goods.BrushResponse;
import com.william.yun.yunliwuli.api.response.goods.GoodsAllResponse;
import com.william.yun.yunliwuli.api.response.goods.LabelQueryResponse;
import com.william.yun.yunliwuli.service.impl.GoodsServiceImpl;
import com.william.yun.yunliwuli.service.impl.LabelServiceImpl;

/**
 * 商品
 */
public class GoodsApi extends BaseApi{
    /**
     * 添加商品
     * @param request
     * @param token
     * @return
     */
    public HttpResponse addGoods(GoodsRequest request, String token){
        JSONObject jsonObject = new GoodsServiceImpl().insertGoods(getJsonParam(request), token);
        return JSONObject.toJavaObject(jsonObject, HttpResponse.class);
    }

    /**
     * 删除商品
     * @param request
     * @param token
     * @return
     */
    public HttpResponse deleteGoods(GoodsRequest request, String token){
        JSONObject jsonObject = new GoodsServiceImpl().removeGoods(getJsonParam(request), token);
        return JSONObject.toJavaObject(jsonObject, HttpResponse.class);
    }

    /**
     * 修改商品
     * @param request
     * @param token
     * @return
     */
    public HttpResponse updateGoods(GoodsRequest request, String token){
        JSONObject jsonObject = new GoodsServiceImpl().updateGoods(getJsonParam(request), token);
        return JSONObject.toJavaObject(jsonObject, HttpResponse.class);
    }

    /**
     * 推送单个商品
     * @param request
     * @param token
     * @return
     */
    public BrushResponse brush(BrushRequest request, String token){
        JSONObject jsonObject = new GoodsServiceImpl().brush(getJsonParam(request), token);
        return JSONObject.toJavaObject(jsonObject, BrushResponse.class);
    }

    /**
     * 价签查询绑定商品
     * @param mac
     * @param token
     * @return
     */
    public LabelQueryResponse labelQuery(String mac, String token){
        JSONObject labelQuery = new LabelServiceImpl().getLabelQuery(mac, token);
        return JSONObject.toJavaObject(labelQuery, LabelQueryResponse.class);
    }

    /**
     * 商品列表
     * @param request
     * @param token
     * @return
     */
    public GoodsAllResponse goodsAll(GoodsAllRequest request, String token){
        JSONObject goodsAll = new GoodsServiceImpl().getGoodsAll(getJsonParam(request), token);
        return JSONObject.toJavaObject(goodsAll, GoodsAllResponse.class);
    }




}
